import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { ManhuaTable } from '../table/manhua.table';
import { Util } from '../../../util/util';

@Component({
    selector: 'manhua-search',
    templateUrl: './manhua.search.html',
    styleUrls: ['./manhua.search.css']
})

export class ManhuaSearch {

    @ViewChild('manhuaTable') childComponent: ManhuaTable;

    searchTitle: string = '';

    constructor(private util: Util) {
        
    }
    onKey(event){
        console.log(event);

        if(event.keyCode == '13'){
            this.submit();
        }
    }
    // btn
    submit() {
        if (this.searchTitle == '') {
            return;
        }
        this.util.store().set('search', this.searchTitle);
        this.childComponent.outputHandel({ search: this.searchTitle },true);
    }

    ngAfterViewInit() {

        setTimeout(() => {
            this.searchTitle = this.util.store().get('search');
            this.childComponent.outputHandel({ search: this.searchTitle },true);
        }, 100);

    }
}